﻿
//  该类为齿轮案绘制
//vesion 1.0
//author 夏天的树人

package org.summerTree.graphics
{
	import flash.geom.Point;
	public class GearWheel extends Base 
	{
		//private var LineColor:uint=0x000000;//默认是黑色
		public function GearWheel()
		{

		}
		override public function clone():*
		{
			return new GearWheel();
		}
		
		public function CreatGearWheel(long_radius:Number,short_radius:Number,n:int=5,fillcolor:uint=0xffffff,alpha:Number=1):void
		{
			
			this.graphics.lineStyle(1,color);
			if (n <= 0) return;		
			var angle:Number=Math.PI / n;
			var tempArray:Array=new Array();
			var key:Boolean=true;
			this.graphics.beginFill(fillcolor,alpha);
			var l_px:Number;
			var l_py:Number;
			var s_px:Number;
			var s_py:Number;
			
			for (var i:int=0; i< n*2 ; i++)
			{				
				if (i%2==0)
				{
					l_px=long_radius * Math.cos(i * angle);
					l_py=long_radius * Math.sin(i * angle);
					tempArray.push(new Point(l_px,l_py));
					
					if(key)
					{
						key=false;
					   s_px=short_radius * Math.cos(i * angle);
					   s_py=short_radius * Math.sin(i * angle);
					    tempArray.push(new Point(s_px,s_py));
					}
					
				}
				else
				{
					s_px=short_radius * Math.cos(i * angle);
				    s_py=short_radius * Math.sin(i * angle);
					tempArray.push(new Point(s_px,s_py));
					if(!key)
					{
						key=true;
					     l_px=long_radius * Math.cos(i * angle);
					     l_py=long_radius * Math.sin(i * angle);
					    tempArray.push(new Point(l_px,l_py));
					}
					
				}
											
			}
			this.graphics.beginFill(fillcolor,alpha);
			this.graphics.moveTo(tempArray[0].x,tempArray[0].y);
			for (var j:int=0; j< tempArray.length; j++)
			{
				
				drawPoint(tempArray[j]);
			}
			this.graphics.lineTo(tempArray[0].x,tempArray[0].y);
			this.graphics.endFill();
			
			var len:Number=long_radius>short_radius ?long_radius:short_radius;
			this.graphics.drawCircle(0,0,len*0.3);
			this.graphics.drawCircle(0,0,len*0.1);			
		}
		
		//绘制线程序
		private function drawPoint(point:Point):void
		{
			this.graphics.lineTo(point.x,point.y);
		}
////设置颜色
//		public function set color(value:uint):void
//		{
//			this.LineColor=value;
//		}
//		//获取颜色
//		public function get color():uint
//		{
//			return this.LineColor;
//		}
		////清除图像
//		public function clear():void
//		{
//			this.graphics.clear();
//		}		
	}
}